package org.mspring.mlog.entity;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.mspring.mlog.entity.security.User;

/**
 * 消息表
 * 
 * @author Gao Youbo
 * @since 2013年7月22日
 */
@Entity
@Table(name = "message")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Message implements Serializable {

    private static final long serialVersionUID = 4081685726153561888L;

    private Long id;
    private User sender;
    private User receiver;
    private MessageText messageText;
    private Boolean readed;

    public Message() {
        // TODO Auto-generated constructor stub
    }

    public Message(Long id) {
        super();
        this.id = id;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, nullable = false, length = 30)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY, optional = true, targetEntity = User.class)
    @JoinColumn(name = "sender")
    public User getSender() {
        return sender;
    }

    public void setSender(User sender) {
        this.sender = sender;
    }

    @ManyToOne(fetch = FetchType.LAZY, optional = false, targetEntity = User.class)
    @JoinColumn(name = "receiver", nullable = false)
    public User getReceiver() {
        return receiver;
    }

    public void setReceiver(User receiver) {
        this.receiver = receiver;
    }

    @ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.ALL }, optional = false, targetEntity = MessageText.class)
    @JoinColumn(name = "message_text", nullable = false)
    public MessageText getMessageText() {
        return messageText;
    }

    public void setMessageText(MessageText messageText) {
        this.messageText = messageText;
    }

    @Column(name = "readed", nullable = false)
    public Boolean getReaded() {
        return readed;
    }

    public void setReaded(Boolean readed) {
        this.readed = readed;
    }

}
